library(data.table)

##load data
data <- read.table("C:/Users/Steffi/Documents/=Uni/SpezPhy/Daten/ki_0000foc3_000rug_201110010000_201110312355_eat_ca05_cti05_0005.dat", header = T, sep = ",", fill = T)

##function to calculate the minimum or maximum of a variable in an defined time 
##segment. Parameters:
##datatable = table of data
##variable = column name of parameter of whom the min/max should be calculated
##extremum = type of extremum -> "min"or "max"
##dateVariable = column name of date
##timeMin = begin of time segment of whom the min/max value should be calculated
##timeMax = end of time segment of whom the min/max value should be calculated

MinMax <- function(datatable,
                   variable,
                   extremum,
                   dateVariable,
                   timeMin,
                   timeMax) {
  
  ##convert date Variable to character
  as.character(data$Datetime)
  
  ##get the min and max index of the time segment
  dateBeginIndex <- like(data$Datetime, pattern = timeMin)
  dateEndIndex <- like(data$Datetime, pattern = timeMax)
    
  ##cut data
  data_cut <-data[dateBeginIndex:dateEndIndex,]
  
  ##calculates min or max value
  return(if(extremum == "min") {
    (min(data_cut$variable, na.rm = TRUE))
    } else {
    (max(data_cut$variable, na.rm = TRUE))
    })
  
}

##Example
Ausgabe <- MinMax(datatable = data,
                  variable = Ta_200,
                  extremum = "min",
                  dateVariable = Datetime,
                  timeMin = "2011-10-01 00:00:00",
                  timeMax = "2011-10-02 00:00:00")
